import { _decorator, Component, Node } from 'cc';
import { DialogFrame } from './components/frame/DialogFrame';
import { MenuComponent } from './components/MenuComponent'
import { Logger } from './utils/log';
import { RootStore } from './mixin';
const { ccclass, property, uniquelyReferenced } = _decorator;


@uniquelyReferenced
@ccclass('ComponentManager')
export class ComponentManager {

    @property({
        tooltip: '对话框管理',
        displayName: '对话框管理',
        type: DialogFrame,
    })
    dialogFrame: DialogFrame;

    @property({
        tooltip: 'MenuComponent: 菜单组件',
        displayName: '菜单组件',
        type: MenuComponent,
    })
    menuComponents: MenuComponent;

    store: RootStore = RootStore.instance

    #log = new Logger('#组件管理#')


    startMajor(content: LDContent.DialogContent) {
        if(!this.dialogFrame.node.active) this.dialogFrame.node.active = true
        this.#log.debug('@startMajor()', content)
        this.#log.debug('当前的数据:', this.store.currentFrame)
        // this.#log.debug('当前对话框状态', this.dialogFrame.majorContent)
        if(this.dialogFrame.minorContent.node.active) this.dialogFrame.minorContent.node.active = false
        if(this.dialogFrame.naratorContent.node.active) this.dialogFrame.naratorContent.node.active = false

        this.dialogFrame.majorContent.context = content.dialog.what.text

        if(!this.dialogFrame.majorContent.node.active) return this.dialogFrame.majorContent.node.active = true

        this.dialogFrame.majorContent.refreshContext()
    }

    startMinor(content: LDContent.DialogContent) {
        if(!this.dialogFrame.node.active) this.dialogFrame.node.active = true
        this.#log.debug('@startMinor()', content)
        this.#log.debug('当前的数据:', this.store.currentFrame)
        if(this.dialogFrame.majorContent.node.active) this.dialogFrame.majorContent.node.active = false
        if(this.dialogFrame.naratorContent.node.active) this.dialogFrame.naratorContent.node.active = false

        const role = this.store.getRole(content.dialog.who.roleId)
        this.dialogFrame.minorContent.nickNamePlacehold = role.nickname
        this.dialogFrame.minorContent.context = content.dialog.what.text

        if(!this.dialogFrame.minorContent.node.active) return this.dialogFrame.minorContent.node.active = true

        this.dialogFrame.minorContent.refreshContext()
    }


    startNarator(content: LDContent.DialogContent) {
        if(!this.dialogFrame.node.active) this.dialogFrame.node.active = true
        this.#log.debug('@startNarator()', content)
        if(this.dialogFrame.majorContent.node.active) this.dialogFrame.majorContent.node.active = false
        if(this.dialogFrame.minorContent.node.active) this.dialogFrame.minorContent.node.active = false

        this.dialogFrame.naratorContent.context = content.dialog.what.text
        if(!this.dialogFrame.naratorContent.node.active) return this.dialogFrame.naratorContent.node.active = true

        this.dialogFrame.naratorContent.refreshContext()
    }

}

export const componentManager = new ComponentManager()
